// @ts-ignore
import pako from "@/libs/pako.esm.js";

type Pack = {
    msgtype: "Src" | "Gzip";
    msginfo: string;
    msgtoken: string;
};

// 解压接口的压缩类型数据
export const unpack = (data: Pack) => {
    if (data.msgtype == "Src") return JSON.parse(data.msginfo);
    else {
        let strData = atob(data.msginfo);
        return JSON.parse(new TextDecoder("utf-8").decode(pako.inflate(new Uint8Array(strData.split("").map((x) => x.charCodeAt(0)))) as Uint8Array));
    }
};
// 将对象转换成编辑接口需要的数组格式（{ a: "1" } => [{ name: "a", value: "1" }]）
export const objToEditArr = (object: any) => {
    let arr = [];
    for (let key in object) arr.push({ name: key, value: object[key] });
    return arr;
};
